home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / logiso.000 / logiso / Utils / RCS / follow_link,v < prev    next >
Encoding:
Text File  |  1995-03-24  |  1.2 KB  |  77 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     VER_0_3:1.2
  5.     VER_0_2:1.1;
  6. locks; strict;
  7. comment    @# @;
  8.  
  9.  
  10. 1.2
  11. date    95.03.24.11.43.35;    author coulter;    state Exp;
  12. branches;
  13. next    1.1;
  14.  
  15. 1.1
  16. date    95.02.18.08.36.38;    author coulter;    state Exp;
  17. branches;
  18. next    ;
  19.  
  20.  
  21. desc
  22. @return a path to the ultimate destination of a link
  23. @
  24.  
  25.  
  26. 1.2
  27. log
  28. @Checkin version for 0.3 distribution.
  29. @
  30. text
  31. @#! /bin/ksh
  32. USAGE='USAGE: follow_link FILE_PATH
  33.    If FILE_PATH is not a link, echo path, else, echo a path (relative or
  34.    absolute) to the ultimate destination of the link).
  35. '
  36. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  37.  
  38. # Process parameters
  39.  
  40.    if [ $# -ne 1 ]
  41.    then
  42.       echo "$USAGE" >&2
  43.       exit 1
  44.    fi
  45.    FILE_PATH="$1"; shift
  46.  
  47. # Do it
  48.  
  49.    if [ ! -L "$FILE_PATH" ]
  50.    then
  51.       echo "$FILE_PATH"
  52.       exit 0
  53.    fi
  54.    LINK="$FILE_PATH"
  55.    while [ -L "$LINK" ]
  56.    do
  57.       NEW_LINK="$(ls -l "$LINK" | cut -c56-500 | sed -e 's/^.* //')"
  58.       if [ "$NEW_LINK" = "${NEW_LINK#/}" ]
  59.       then
  60.      # NEW_LINK is relative, add dirname of FILE_PATH
  61.      DIR_PATH="$(dirname "$LINK")"
  62.      NEW_LINK="$DIR_PATH/${NEW_LINK}"
  63.       fi
  64.       LINK="$NEW_LINK"
  65.    done
  66.    echo "$LINK"
  67. @
  68.  
  69.  
  70. 1.1
  71. log
  72. @Checkpoint version before fixing /usr/bin install
  73. @
  74. text
  75. @d6 1
  76. @
  77.